package com.laoniu.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class ServletUtils {

    public static HttpServletRequest getRequest(){
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return servletRequestAttributes.getRequest();
    }

    public static String getRequestIp(){
        HttpServletRequest request = getRequest();
        return request.getRemoteAddr();
    }

    public static String getDevice(){
        HttpServletRequest request = getRequest();
        return request.getHeader("user-agent");
    }

    public static String getUrl(){
        return getRequest().getRequestURI();
    }
}
